I tried deploying flask app in AWS Elastic Beanstalk

I tried deploying flask app in AWS Elastic Beanstalk

Clock Icon2021.09.10

この記事は公開されてから1年以上経過しています。情報が古い可能性がありますので、ご注意ください。

i am preparing for AWS DVA certification exam and come in touch with "platform as a service" AWS Elastic Beanstalk i thought to give it a try .

i am aayush and below i shared my learning.

Overview of Elastic Beanstalk

Elastic Beanstalk is a developer centric view of deploying an aplication on AWS

managed service:

  1. automatically handles capacity provisioning load balancing,scaling, application health monitoring instance configuration etc
  2. just the application code is the responsibility of the developer

we still have full control over configuration

lets try :

  • creating vitualenvironment and activating virtualenvironment


python3 -m pip install --user virtualenv
python3 -m venv env
source</span> env/bin/activate
pip install flask
pip freeze > requirements.txt
  • creating falask app

Note: aws ElasticBeanStalk expects the veriable to be application instead off app therefore save the python file as application.py

from flask import Flask
from datetime import datetime
import re

application = app = Flask(__name__)
@app.route("/")
def home():
return "Hello, developersIO!"
@app.route("/hello/<name>")
def hello_there(name):
now = datetime.now()
formatted_now = now.strftime("%A, %d %B, %Y at %X")
# Filter the name argument to letters only using regular expressions. URL arguments
# can contain arbitrary text, so we restrict to safe characters only.
match_object = re.match("[a-zA-Z]+", name)
if match_object:
clean_name = match_object.group(0)
else:
clean_name = "Friend"

content = "Hello there, " + clean_name + "! It's " + formatted_now
return content

ziping requirements and application.py file to ebsblog.zip

zip ebsblog.zip requirements.txt application.py

 

 

  • deploy it in elastic beanstalk using console

  • open elastic beanstalk from aws management console
  • create application
    • Application name:ebsblog
    • Platform :Python
    • Application code:Upload your code
    • Local file: choose ebsblog.zip file
    • click create application
  • open the link

we have successfully deployed a flask application in aws elastic bean stalk.

References:

https://searchaws.techtarget.com/tutorial/Learn-how-to-deploy-a-Flask-app-to-AWS-Elastic-Beanstalk

deploying flask app using ebcli:

https://dev.classmethod.jp/articles/tut-eb-py-flask/

Share this article

facebook logohatena logotwitter logo

© Classmethod, Inc. All rights reserved.